﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BOHVote.Common;
using BOHVote.BLL;
using System.Data;

namespace BOH.Information.Report
{
    public partial class printGovrenListReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string ApplyPeriod = string.Empty;
            string GovrenID = string.Empty;
            string GovrenName = string.Empty;
            this.Title = common.getAppSetting("AppName");
            if (!IsPostBack)
            {
                GovrenID = Request.QueryString["GovrenID"];
                ApplyPeriod = Request.QueryString["ApplyPeriod"];
                //hiddenApplyPeriod.Value = ApplyPeriod;
                //hiddenGovrenID.Value = GovrenID;
                GovrenName = UnitClass.GetGovernName(GovrenID);
                labGovernName.Text = GovrenName;
                this.Title = common.getAppSetting("AppName");
                string strCount = string.Empty;
                //XSD.PersonalInfo xsd = BindReport(GovrenID, ApplyPeriod, out strCount);
                //ReportViewBind(xsd, GovrenName, ApplyPeriod + "年度", strCount);
                XSD.PersonalInfo dst = dstGovernList(GovrenID, ApplyPeriod);
                BindGovrenList(dst);
            }
        }

        public void BindListofGovren()
        {
            string ApplyPeriod = string.Empty;
            string GovrenID = string.Empty;
            string GovrenName = string.Empty;
            GovrenName = UnitClass.GetGovernName(GovrenID);
            labGovernName.Text = GovrenName;
            GovrenID = Request.QueryString["GovrenID"];
            ApplyPeriod = Request.QueryString["ApplyPeriod"];
            //hiddenApplyPeriod.Value = ApplyPeriod;
            //hiddenGovrenID.Value = GovrenID;
            XSD.PersonalInfo dst = dstGovernList(GovrenID, ApplyPeriod);
            BindGovrenList(dst);
        }

        public XSD.PersonalInfo dstGovernList(string GovrenID, string ApplyPeriod)
        {
            DataSet dst = ApplyClass.getApplyInfo("", "", GovrenID, ApplyPeriod);

            XSD.PersonalInfo personalXSD = new BOH.XSD.PersonalInfo();
            int i = 0;
            foreach (DataRow dr in dst.Tables[0].Rows)
            {
                DataRow drNew = personalXSD.Tables["PersonalInfo"].NewRow();
                drNew["NO"] = ++i;
                drNew["ApplyName"] = dr["Apply_Name"].ToString();
                drNew["UnitGovernName"] = dr["UnitGovernName"].ToString();
                drNew["ApplyPeriod"] = dr["ApplyPeriodID"].ToString();
                drNew["Gender"] = dr["Gender"].ToString();
                if (!string.IsNullOrEmpty(dr["Birthday"].ToString()))
                    drNew["Birthday"] = Convert.ToDateTime(dr["Birthday"].ToString()).ToString("yyyy-MM"); //common.changeDateFormatToDate(dr["Birthday"].ToString()).ToString("yyyy-MM-dd");
                else
                    drNew["Birthday"] = "-";

                drNew["EducationLevel"] = dr["EducationLevel"].ToString();
                drNew["IDCard"] = dr["IDCard"].ToString();
                drNew["School"] = dr["School"].ToString();

                if (!string.IsNullOrEmpty(dr["GraduationDate"].ToString()))
                    drNew["GraduationDate"] = Convert.ToDateTime(dr["GraduationDate"].ToString()).ToString("yyyy-MM");// common.changeDateFormatToDate(dr["GraduationDate"].ToString()).ToString("yyyy-MM-dd");
                else
                    drNew["GraduationDate"] = "-";

                drNew["CurrentJobRank"] = dr["CurrentJobRankID"].ToString();
                drNew["ApplyType"] = dr["ApplyType"].ToString();
                drNew["SpecialityID"] = dr["SpecialityID"].ToString();
                drNew["JobRankID"] = dr["JobRankID"].ToString();
                drNew["SubjectID"] = dr["SubjectID"].ToString();

                if (!string.IsNullOrEmpty(dr["JobDate"].ToString()))
                    drNew["JobDate"] = Convert.ToDateTime(dr["JobDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["JobDate"] = "-";

                // common.changeDateFormatToDate(dr["JobDate"].ToString()).ToString("yyyy-MM-dd");
                if (!string.IsNullOrEmpty(dr["ConversionDate"].ToString()))
                    drNew["ConversionDate"] = Convert.ToDateTime(dr["ConversionDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["ConversionDate"] = "-";

                drNew["JobTerm"] = dr["JobTerm"].ToString();
                drNew["FixedJob"] = dr["FixedJob"].ToString();
                drNew["ForeignLanguageName"] = dr["ForeignLanguageName"].ToString();
                drNew["ForeignLanguageResult"] = dr["ForeignLanguageResult"].ToString();
                drNew["PoliticsResult"] = dr["PoliticsResult"].ToString();
                drNew["JobResult"] = dr["JobResult"].ToString();
                drNew["ComputerResult"] = dr["ComputerResult"].ToString();
                drNew["ApplyPrintID"] = dr["ApplyPrintID"].ToString();

                personalXSD.Tables["PersonalInfo"].Rows.Add(drNew);

            }
            return personalXSD;
        }

        public void BindGovrenList(XSD.PersonalInfo dst)
        {
            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                AspNetPager1.RecordCount = dst.Tables[0].Rows.Count;
                if (AspNetPager1.RecordCount != 0)
                {
                    labNoRecord.Visible = false;
                    AspNetPager1.Visible = true;
                    PagedDataSource pds = new PagedDataSource();
                    pds.DataSource = dst.Tables[0].DefaultView;
                    pds.AllowPaging = true;
                    pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                    pds.PageSize = AspNetPager1.PageSize;
                    GovernList.DataSource = pds;
                    GovernList.DataBind();
                }
                else
                {
                    GovernList.DataSource = null;
                    GovernList.DataBind();
                    AspNetPager1.Visible = false;
                    labNoRecord.Visible = true;
                }
            }
            else
            {
                AspNetPager1.Visible = false;
                labNoRecord.Visible = true;
                GovernList.DataSource = null;
                GovernList.DataBind();
            }
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindListofGovren();
        }
    }
}
